//
//  AddOrderViewController.m
//  mcosApp
//
//  Created by YaSha_Tom on 2018/12/13.
//  Copyright © 2018年 YaSha-Tom. All rights reserved.
//

#import "AddOrderViewController.h"
#import <BRPickerView.h>

@interface AddOrderViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,copy)NSArray *titleArray;
@property (nonatomic,strong) NSMutableArray *contentArray;
@property (nonatomic,strong) NSMutableDictionary *parameterDic;
@end

@implementation AddOrderViewController
- (NSMutableDictionary *)parameterDic {
    if (!_parameterDic) {
        _parameterDic = [NSMutableDictionary dictionary];
    }
    return _parameterDic;
}
- (NSMutableArray *)contentArray{
    if (!_contentArray) {
        _contentArray = [NSMutableArray array];
    }
    return _contentArray;
}
- (NSArray *)titleArray {
    if (!_titleArray) {
        _titleArray = @[@"姓名",@"手机",@"地址信息",@"楼盘",@"房号",@"房屋户型",@"房产证面积(m²)",@"房屋类型"];
    }
    return _titleArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"生成订单";
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *button = [[UIButton alloc]initWithFrame:CGRects(0, 30, 59, 14)];
    //右边按钮
    [button addTarget:self action:@selector(saveOrder) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"生成订单" forState:UIControlStateNormal];
    button.titleLabel.font=[UIFont systemFontOfSize:17.0*BIZ];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = item1;
    [self initUI];
    [self dataProcessing];
    [self doNetworkingDic];
}
- (void)dataProcessing {
    [self.parameterDic setValue:self.model.id forKey:@"id"];
    [self.contentArray addObject:self.model.name];
    [self.parameterDic setValue:self.model.name forKey:@"name"];
    [self.contentArray addObject:self.model.mobile];
    [self.parameterDic setValue:self.model.mobile forKey:@"mobile"];
    [self.contentArray addObject:[NSString stringWithFormat:@"%@%@%@",self.model.province,self.model.city,self.model.area]];
    [self.parameterDic setValue:self.model.province forKey:@"province"];
    [self.parameterDic setValue:self.model.provinceCode forKey:@"provinceCode"];
    [self.parameterDic setValue:self.model.city forKey:@"city"];
    [self.parameterDic setValue:self.model.cityCode forKey:@"cityCode"];
    [self.parameterDic setValue:self.model.area forKey:@"area"];
    [self.parameterDic setValue:self.model.areaCode forKey:@"areaCode"];
    [self.contentArray addObject:[NSString stringWithFormat:@"%@%@",self.model.buildName,self.model.buildGroupName]];
    NSLog(@"------%@",self.model.buildingId);
    [self.parameterDic setValue:self.model.buildingId forKey:@"buildingId"];
    [self.parameterDic setValue:self.model.buildingGroupId forKey:@"buildingGroupId"];
    [self.contentArray addObject:self.model.address];
    [self.parameterDic setValue:self.model.address forKey:@"address"];
    [self.contentArray addObject:[NSString stringWithFormat:@"%@室 %@厅 %@厨房 %@卫 %@阳台",self.model.hxShi,self.model.hxTing,self.model.hxChu,self.model.hxWei,self.model.hxYangtai]];
    [self.parameterDic setValue:self.model.hxShi forKey:@"hxShi"];
    [self.parameterDic setValue:self.model.hxTing forKey:@"hxTing"];
    [self.parameterDic setValue:self.model.hxChu forKey:@"hxWei"];
    [self.parameterDic setValue:self.model.hxWei forKey:@"hxChu"];
    [self.parameterDic setValue:self.model.hxYangtai forKey:@"hxYangtai"];
    [self.contentArray addObject:[NSString stringWithFormat:@"%@",self.model.size]];
    [self.parameterDic setValue:self.model.size forKey:@"size"];
    [self.contentArray addObject:self.model.type];
    [self.parameterDic setValue:@"256" forKey:@"type"];
    [self.parameterDic setValue:@"2000" forKey:@"bookMoney"];
    [self.parameterDic setValue:@"149" forKey:@"yxGrade"];
    [self.tableView reloadData];
}

- (void)initUI {
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;//取消cell 的点击效果
    cell.textLabel.text = self.titleArray[indexPath.row];
    if (self.contentArray.count > 0) {
        if ([self.contentArray[indexPath.row] length]>0) {
            cell.accessoryType = UITableViewCellAccessoryNone;//cell没有任何的样式
        }else{
             cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头，距离右边有十几像素；
        }
        cell.detailTextLabel.text = self.contentArray[indexPath.row];
    }
    return cell;
}

- (void)doNetworkingDic{
    NSString *urlString = [NSString stringWithFormat:@"%@%@",Domain,getOrderRebokDic];
    [YSNetManager ys_request_GETWithUrlString:urlString isNeedCache:NO parameters:nil successBlock:^(id response) {
        NSLog(@"成功%@",response);
        if ([response[@"code"]  isEqual: @1]) {
           
        }else{
            [QMUITips showSucceed:response[@"msg"] inView:self.view hideAfterDelay:1];
        }
    } failureBlock:^(NSError *error) {
        NSLog(@"失败%@",error);
    } progress:nil];
}

- (void) saveOrder{
    NSString *urlString = [NSString stringWithFormat:@"%@%@",Domain,createOrder];
    [YSNetManager ys_request_GETWithUrlString:urlString isNeedCache:NO parameters:self.parameterDic successBlock:^(id response) {
        NSLog(@"成功%@",response[@"msg"]);
        [QMUITips showSucceed:@"订单创建成功" inView:self.view hideAfterDelay:1];
        [self.navigationController popViewControllerAnimated:YES];
    } failureBlock:^(NSError *error) {
        NSLog(@"失败%@",error);
    } progress:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
